package com.nanning.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nanning.common.utils.StringUtils;
import com.nanning.system.domain.ImportRecord;
import com.nanning.system.mapper.ImportRecordMapper;
import com.nanning.system.service.IImportRecordService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 数据导入记录表 服务实现类
 * </p>
 *
 * @author zhurenwang
 * @since 2025-05-07
 */
@Service
public class ImportRecordServiceImpl extends ServiceImpl<ImportRecordMapper, ImportRecord> implements IImportRecordService {

    @Override
    public List<ImportRecord> list(ImportRecord record) {
        return lambdaQuery()
                .like(StringUtils.isNotEmpty(record.getFileName()), ImportRecord::getFileName, record.getFileName())
                .eq(Objects.nonNull(record.getFileType()), ImportRecord::getFileType, record.getFileType())
                .orderByDesc(ImportRecord::getCreateTime).list();
    }

    @Override
    public boolean add(ImportRecord record) {
        return save(record);
    }

    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public void save(String originalFilename, int type) {
        ImportRecord record = new ImportRecord();
        record.setFileName(originalFilename);
        record.setFileType(type);
        save(record);
    }
}
